package com.wframe.project.former.web.information;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.frame.database.JdataBean;
import com.frame.database.util.ConditionMap;
import com.frame.pageform.DataPageForm;
import com.wframe.project.former.dataservices.information.SkeywordService;

public class SkeywordPage extends DataPageForm{

	private SkeywordService keywordService=SkeywordService.getIntance();
	private JdataBean bean;
	
	@Override
	public String execute() throws Exception {
//		ConditionMap cond=new ConditionMap();
//		cond.addOrder("id", false);
		setPagination(keywordService.queryKeyword(bean,getPageSize_(), getPageNum()));
		return "/webadmin/information/keywordList.jsp";
	}
	
	@Override
	public String show() throws Exception {
		// TODO Auto-generated method stub
		if(bean!=null && StringUtils.isNotBlank(bean.getString("id")))
			bean=keywordService.getBean(bean.getString("id"));
		else{
			bean=new JdataBean();
			bean.put("url", "http://");
		}
		return "/webadmin/information/keywordEdit.jsp";
	}

	@Override
	public String toDel() throws Exception {
		keywordService.del(bean.getString("id"));
		return getJsonObject().toString();
	}

	@Override
	public boolean toUpdate() throws Exception {
		// TODO Auto-generated method stub
		if(StringUtils.isNotBlank(bean.getString("id"))){
			Map key=new HashMap();
			key.put("id", bean.getString("id"));
			keywordService.update(bean.getDataMap(), key);
		}else{
			bean.put("intime", new Date());
			keywordService.save(bean.getDataMap());
		}
		getJsonObject().getJsonPage().closeWin("ok");
		return false;
	}

	public JdataBean getBean() {
		return bean;
	}

	public void setBean(JdataBean bean) {
		this.bean = bean;
	}

}
